package com.dhecp.project.system.controller;

import java.util.List;
import java.util.Map;

import com.dhecp.framework.shiro.service.SysPasswordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.dhecp.common.annotation.Log;
import com.dhecp.common.core.controller.BaseController;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.common.utils.poi.ExcelUtil;
import com.dhecp.project.system.domain.SysLoginLog;
import com.dhecp.project.system.service.SysLoginLogService;

/**
 * 系统访问记录
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/system/loginlog")
public class SysLoginLogController extends BaseController
{
    private String prefix = "system/loginlog";

    @Autowired
    private SysLoginLogService loginLogService;

    @Autowired
    private SysPasswordService passwordService;

    @RequiresPermissions("system:loginlog:view")
    @GetMapping()
    public String loginlog()
    {
        return prefix + "/loginlog";
    }

    @RequiresPermissions("system:loginlog:list")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params)
    {
        startPage();
        List<SysLoginLog> list = loginLogService.queryLoginLogList(params);
        return getDataTable(list);
    }

    @Log(title = "登陆日志", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:loginlog:export")
    @RequestMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam Map<String, Object> params)
    {
        List<SysLoginLog> list = loginLogService.queryLoginLogList(params);
        ExcelUtil<SysLoginLog> util = new ExcelUtil<SysLoginLog>(SysLoginLog.class);
        return util.exportExcel(list, "登陆日志");
    }

    @RequiresPermissions("system:loginlog:delete")
    @Log(title = "登陆日志", businessType = BusinessType.DELETE)
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(loginLogService.deleteLoginLogByIds(ids));
    }
    
    @RequiresPermissions("system:loginlog:delete")
    @Log(title = "登陆日志", businessType = BusinessType.CLEAN)
    @RequestMapping("/clean")
    @ResponseBody
    public AjaxResult clean()
    {
        loginLogService.cleanLoginLog();
        return success();
    }

    @RequiresPermissions("system:loginlog:unlock")
    @Log(title = "账户解锁", businessType = BusinessType.OTHER)
    @RequestMapping("/unlock")
    @ResponseBody
    public AjaxResult unlock(String loginName)
    {
        passwordService.unlock(loginName);
        return success();
    }
}
